<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

class AdminModel extends Model
{
    use HasFactory;

    protected $table = 'admin';
    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储

    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    static public function test()
    {
        return 'abc';
    }

    //获取审批人列表
    static public function getApproverList($parentId)
    {
        return SELF::select(
                        'id',
                        'username',
                        'nickname',
                        'mobile',
                        'parent_id'
                    )
                    ->where('parent_id', $parentId)
                    ->where('delete_flag', 0)
                    ->orWhere('id', $parentId)
                    ->orderBy('id', 'ASC')
                    ->get();
    }

    //用户列表
    static public function userList($parentId, $data)
    {
        return SELF::select(
                        'id',
                        'username',
                        'nickname',
                        'mobile',
                        'is_active',
                        'updated_at'
                    )
                    ->where([
                        'parent_id' => $parentId,
                        'delete_flag' => 0
                    ])
                    ->orderBy('id', 'DESC')
                    ->paginate($data['pageSize'],['*'], '',$data['currentPage']);
    }
}
